import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/api-rpa/system/list',
  save = '/api-rpa/system/save',
  edit = '/api-rpa/system/save',
  get = '/api-rpa/system/get',
  delete = '/api-rpa/system/delete',
  deleteBatch = '/api-rpa/system/deleteBatch',
  getAllSystemList = '/api-rpa/system/all',
  exportXls = '/api-rpa/system/export',
  importExcel = '/api-rpa/system/import',
}

/**
 * 导出api
 */
export const getExportUrl = Api.exportXls;

export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => {
  return defHttp.get({ url: Api.list, params });
};

/**
 * 删除系统
 */
export const deleteSystem = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除系统
 * @param params
 */
export const batchDeleteSystem = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新系统
 * @param params
 */
export const saveOrUpdateSystem = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 查询详情
 * @param params
 */
export const getSystemById = (params) => {
  return defHttp.get({ url: Api.get, params });
};

/**
 * 所有系统
 * @param params 
 * @returns 
 */
export const getAllSystemList = (params) => {
  return defHttp.get({ url: Api.getAllSystemList, params });
};
